// 创建者:   Harling
// 创建时间: 2023-12-01 14:09:33
// 备注:     由PIToolKit工具生成

Shader "BakeTest/S_BaseTransAlphahaOffset" 
{
	Properties 
	{
		_UV_Tiling("UV_Tiling", Vector) = (1, 1, 0, 0)
		_Rotate("Rotate", Float) = 0
		[NoScaleOffset]_T_BaseColor("T_BaseColor", 2D) = "white" {}
		[HDR]_BaseColor_Tint("BaseColor_Tint", Color) = (0, 0, 0, 0)
		[NoScaleOffset]_T_Offset("T_Offset", 2D) = "white" {}
		[HDR]_Offset_Tint("Offset_Tint", Color) = (0, 0, 0, 0)
		_Offset_Speed("Offset_Speed", Float) = 0
		_Opacity("Opacity", Float) = 1
	}

	CGINCLUDE
	#pragma target 4.0
	#pragma multi_compile_instancing
			
	#include "UnityCG.cginc"
	#include "Utils.cginc"

	float2 _UV_Tiling;
	float _Rotate;
	float4 _T_Offset_TexelSize;
	float4 _T_BaseColor_TexelSize;
	float4 _Offset_Tint;
	float4 _BaseColor_Tint;
	float _Opacity;
	float _Offset_Speed;

	sampler2D _T_Offset;
	sampler2D _T_BaseColor;

	struct v2f
	{
		float2 UV:TEXCOORD0;
		UNITY_VERTEX_OUTPUT_STEREO
		UNITY_VERTEX_INPUT_INSTANCE_ID 
	};
	
	void Vert(appdata_base adb,uint id:SV_INSTANCEID,uint vid : SV_VertexID,out v2f o,out float4 pos:POSITION)
	{
		UNITY_SETUP_INSTANCE_ID(adb);
		UNITY_TRANSFER_INSTANCE_ID(adb, o);
		UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
				
		pos=UnityObjectToClipPos(adb.vertex);
		o.UV=adb.texcoord;
	}

	void Frag(v2f data,out fixed4 col:SV_TARGET)
	{
		UNITY_SETUP_INSTANCE_ID(data);

		float2 nuv=data.UV*_UV_Tiling;

		nuv-=0.5;
		RotateUV(nuv,_Rotate);
		nuv+=0.5;

		fixed4 basecolor=tex2D(_T_BaseColor,nuv);
		col.a=basecolor.a*_Opacity;

		basecolor*=_BaseColor_Tint;

		nuv=data.UV;
		nuv-=0.5;
		RotateUV(nuv,-90);
		nuv+=0.5;

		float time=_Time.y*_Offset_Speed;

		nuv=nuv+float2(0,time);
		fixed4 offset=tex2D(_T_Offset,nuv)*_Offset_Tint;

		fixed4 result=basecolor+offset;
		col.rgb=result.rgb;
	}
	ENDCG

	SubShader 
	{
		// 修改 RenderType 以匹配透明渲染
		Tags {"RenderType" = "Transparent" "Queue"="Transparent" "DisableBatching"="False"}
		pass
		{
			Tags {"LightMode" = "ForwardBase"}
			Name "FORWARD"
			Blend SrcAlpha OneMinusSrcAlpha
			Cull Back
			ZWrite Off
			ZTest LEqual
			Offset 0, 0
			ColorMask RGBA
			CGPROGRAM
			#pragma vertex Vert
			#pragma fragment Frag
			ENDCG
		}
	}
	//FallBack "Diffuse"
}
